/*
 * FillupEntry.java
 *
 * Copyright (C) 2005 Tommi Laukkanen
 * http://www.substanceofcode.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
package com.substanceofcode.carmanager.model;

import java.util.*;

public class FillupEntry {
    
    private String m_originalRecordString;  /** Original record string */
    private String m_date;          /** Date of this fillup */
    private int m_totalGasLiters;   /** Total liters of gasoline in fillup */
    private int m_pricePerLiter;    /** Price per liter (in cents) */
    private int m_fullFillupFlag;   /** Was this full fillup (1=yes) */
    private int m_totalPrice;       /** Total price of this fillup (in cents) */
    private long m_currentMileage;  /** Current mileage on time of fillup */
    private String m_comment;       /** Free form comment for fillup */
    
    FillupEntry(String date, int gas, int full, int price, int km, String com, String originalRecord) {
        m_date = date;
        m_totalGasLiters = gas;
        m_fullFillupFlag = full;
        m_totalPrice = price;
        m_currentMileage = km;
        m_comment = com;
        m_pricePerLiter = (m_totalPrice*1000) / m_totalGasLiters;
        m_originalRecordString = originalRecord;
    }
    
    public String getOriginalRecord(){ return m_originalRecordString; }
    public String getDate(){ return m_date; }
    public int getGas(){ return m_totalGasLiters; }
    public int getPricePerLiter() { return m_pricePerLiter; }
    public int getFullFillUp(){ return m_fullFillupFlag; }
    public int getPrice(){ return m_totalPrice; }
    public long getKm(){ return m_currentMileage; }
    public String getComment(){ return m_comment; }
    public Date getTime() {
        String date = getDate();
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, Integer.parseInt(date.substring(0,4)));
        c.set(Calendar.MONTH, Integer.parseInt(date.substring(4,6))-1);
        c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date.substring(6,8)));
        return c.getTime();
    }
    
    /**
     * Is this fill-up's entry m_date older than given m_date
     */
    public boolean isOlder(Date date) {
        SubDate thisDate = new SubDate( getTime() );
        SubDate newDate  = new SubDate( date );
        if( thisDate.isOlder( newDate ) ) {
            return true;
        }
        else {
            return false;
        }
            
    }
    
    /**
     * Is this fill-up's entry m_date newer than given m_date
     */
    public boolean isNewer(Date date) {
        SubDate thisDate = new SubDate( getTime() );
        SubDate newDate  = new SubDate( date );
        if( thisDate.isNewer( newDate ) ) {
            return true;
        }
        else {
            return false;
        }
    }    
    
    public void setDate(String d){ m_date = d; }
    public void setGas(int g){ m_totalGasLiters = g; }
    public void setFullFillUp(int f){ m_fullFillupFlag = f; }
    public void setPrice(int p){ m_totalPrice = p; }
    public void setKm(long km){ m_currentMileage = km; }
    public void setComment(String c){ m_comment = c; }
}

